package com.handinglian.system.service.impl;

import com.handinglian.system.entity.UserRoleRelation;
import com.handinglian.system.mapper.UserRoleRelationMapper;
import com.handinglian.system.service.UserRoleRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("userRoleRelationService")
public class UserRoleRelationServiceImpl implements UserRoleRelationService {
    @Autowired
    private UserRoleRelationMapper userRoleRelationMapper;

    @Override
    @Transactional
    public int updateUserRoleRelation(UserRoleRelation userRoleRelation) {
        return userRoleRelationMapper.updateRoleIdByUserId(userRoleRelation.getRoleId(), userRoleRelation.getUserId());
    }

    @Override
    public List<UserRoleRelation> inquireUserRoleRelationByRoleId(Integer roleId) {
        return userRoleRelationMapper.findByRoleId(roleId);
    }

    @Override
    @Transactional
    public int createUserRoleRelation(UserRoleRelation userRoleRelation) {
        return userRoleRelationMapper.insertSelective(userRoleRelation);
    }

    @Override
    @Transactional
    public int deleteUserRoleRelation(Integer userId) {
        return userRoleRelationMapper.deleteByUserId(userId);
    }

    @Override
    @Transactional
    public int batchInsert(List<UserRoleRelation> list) {
        return userRoleRelationMapper.batchInsert(list);
    }
}
